<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	template="/resources/layout/templateInterno.xhtml"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:t="http://myfaces.apache.org/tomahawk"
    xmlns:rich="http://richfaces.org/rich">
    
    
	<ui:define name="body">
		<div class="form">
		<h:form id="formCadastroUsers">
		<h:panelGroup id="pgMensagens">
			  <div>
					<h:messages style="padding:5px" errorClass="errorMessage" infoClass="infoMessage"  />
			</div>
		</h:panelGroup>
		<div  class="field-clear"></div>
		  <t:fieldset id="idfsDadosPessoais"  >
		  <legend>Dados</legend>
		  
				<div class="grid-4-12">
					<h:outputLabel  id="lbNome" class="form-lbl"  value="Nome:"/>
					<h:inputText  id="inptNome" styleClass="form-txt" required="true" requiredMessage="Favor informar o Username." value="#{usersCadastro.users.nome}" />
				</div>
				<div class="grid-4-12">
					<h:outputLabel  id="lbEmail" class="form-lbl"  value="E-mail:"/>
					<h:inputText  id="inptEmail" styleClass="form-txt" style="text-transform:lowercase"  required="true" requiredMessage="Favor informar o email." value="#{usersCadastro.users.email}" />
				</div>
				<div class="field-clear"></div>
				<div class="grid-4-12">
					<h:outputLabel  id="lbUsername" class="form-lbl"  value="Usuário:"/>
					<h:inputText  id="inptUsername" disabled="#{usersCadastro.edicao}" styleClass="form-txt" required="true" style="text-transform:lowercase"  
					requiredMessage="Favor informar o Username." value="#{usersCadastro.users.username}" /> 
					<div class="grid-12-12">(Ex. José Amorim da Silva - josé.silva)</div>
				</div>
				 <div class="field-clear"></div>
					<div class="grid-3-12">
							<h:outputLabel  id="lbAuthorities"  class="form-lbl"  value="Perfil:"/>
							<h:selectOneMenu required="true" label="Autorização" converter="indexConverter" width="170" id="cbAuthorities"  value="#{usersCadastro.authority}">
								  <f:selectItem itemLabel="Selecione..." itemValue=""/>
								   <t:selectItems value="#{usersCadastro.listaAuthority}" var="authority" itemLabel="#{authority.role}" itemValue="#{authority}"/>
								   <a4j:support ajaxSingle="true" event="onchange" reRender="pgExibirPickList,pgIgrejaFrequenta"></a4j:support>
							</h:selectOneMenu>					
					</div>
				 <h:panelGroup id="pgIgrejaFrequenta">
				 	<h:panelGroup  rendered="#{usersCadastro.authority.adminGeral}">
						<div class="grid-3-12">
							<h:outputLabel  id="lbIgreja"  class="form-lbl"  value="Igreja:"/>
							<h:selectOneMenu converter="indexConverter" required="true" label="Igreja Pertence"  id="cbIgreja"  value="#{usersCadastro.users.igreja}">
								   <f:selectItem itemLabel="Selecione..." itemValue=""/>
								   <t:selectItems value="#{usersCadastro.listaIgrejas}" var="igreja" itemLabel="#{igreja.nome}" itemValue="#{igreja}"/>
							</h:selectOneMenu>					
							</div>
					</h:panelGroup>
				</h:panelGroup>
				<h:panelGroup  rendered="#{usersCadastro.edicao}">
					<div class="grid-2-12" >
			  			 <h:outputLabel  id="lbAlterarSenha" class="form-lbl"  value="Alterar Senha:"/>
						 <h:selectBooleanCheckbox  id="checkAlterarSenha"  styleClass="form-txt" value="#{usersCadastro.users.primeiroAcesso}" >	
						 </h:selectBooleanCheckbox>
					</div>	
				</h:panelGroup>
				 <div class="field-clear"></div>
				 <h:panelGroup id="pgExibirPickList">
				 <h:panelGroup id="pgAutorizacao" rendered="#{usersCadastro.authority.authority eq 'ROLE_ADMIN_REGIONAL'}">
					 <div class="grid-10-12">
						<h:outputLabel  id="lbCep" class="form-lbl"  value="Igrejas:"/>
						         <rich:pickList width="240" id="listaUnidadesSelecionadas" value="#{usersCadastro.listaIgrejasSelecionadas}"> 
				            <f:selectItems value="#{usersCadastro.listaSelctItensIgrejas}" />
				        </rich:pickList>	
					</div>
				</h:panelGroup>
				</h:panelGroup>
				
		 </t:fieldset>
		 <div style="padding: 20px" >
			 	<rich:dataTable  rowClasses="odd, even" rows="10"
	                    			styleClass="dataTable rich-table rich-table-cell ui-widget-content ui-grid-content"
                    			width="750" id="usersTable"  var="users" value="#{usersCadastro.listaUsers}" >
				  <f:facet  name="header">
                    <rich:columnGroup >
                    		 <rich:column style="text-align: left"  styleClass="ui-state-default" >
                                <strong><h:outputText value="Usuário" /></strong>
                            </rich:column>
                            <rich:column style="text-align: left"  styleClass="ui-state-default" >
                                <strong><h:outputText value="Nome" /></strong>
                            </rich:column>
                             <rich:column style="text-align: left"  styleClass="ui-state-default" >
                                <strong><h:outputText value="Perfil" /></strong>
                            </rich:column>
                            <rich:column style="text-align: left"  styleClass="ui-state-default" >
                                <strong><h:outputText value="Igreja" /></strong>
                            </rich:column>
                              <rich:column style="text-align: center;"  styleClass="ui-state-default" >
                                <strong><h:outputText value="Ação" /></strong>
                            </rich:column>
                    	</rich:columnGroup>
                  </f:facet>
 				<rich:columnGroup >	
 					<rich:column >
						<h:outputText value="#{users.username}" />
					</rich:column>
 					<rich:column >
						<h:outputText value="#{users.nome}" />
					</rich:column>
					<rich:column >
						<h:outputText value="#{users.perfil}" />
					</rich:column>		
					 <rich:column>
						<h:outputText value="#{users.igreja.nome}" />
					</rich:column>
						<rich:column style="text-align: center;" >
						
						<a4j:commandLink action="#{usersCadastro.editar}" id="editar" ajaxSingle="true" value=" " reRender="idfsDadosPessoais"  >
							<h:graphicImage value="/resources/imagens/ico_editar.gif" id="gIEdidar" styleClass="hidelink"/>
							 <f:setPropertyActionListener target="#{usersCadastro.users}" value="#{users}"/>  
						</a4j:commandLink>
						<a4j:commandLink id="remover" ajaxSingle="true" 
						onclick="Richfaces.showModalPanel('modalPanelConfirmaExcluir');"
						 reRender="pgMensagens,usersTable,idfsDadosPessoais"  >
							 <h:graphicImage value="/resources/imagens/ico_excluir.gif" id="gIExcluirUsers" styleClass="hidelink"/>
							   <f:setPropertyActionListener target="#{usersCadastro.username}" value="#{users.username}"/>
						</a4j:commandLink>
					</rich:column>
				</rich:columnGroup>
			</rich:dataTable>
		</div>
			<div  class="field-clear"></div>
			<div class="grid-2-12">
				<div style="text-align: center;" >
					<a4j:commandButton  ajaxSingle="true" process="idfsDadosPessoais" styleClass="form-button" id="cbSalvarUsers" value="Salvar" reRender="pgMensagens,usersTable,idfsDadosPessoais" action="#{usersCadastro.salvar}" >	</a4j:commandButton>
				</div >
			</div>
			<div class="grid-2-12">
				<div style="text-align: center;" >
					<a4j:commandButton ajaxSingle="true"  styleClass="form-button" id="limpar" value="Limpar" reRender="pgMensagens,usersTable,idfsDadosPessoais" action="#{usersCadastro.limpar}" >	</a4j:commandButton>
				</div >
			</div>
		</h:form>
		</div>
	<rich:modalPanel id="modalPanelConfirmaExcluir" width="280"
					autosized="false" resizeable="false" height="110">
			<div class="form">
			<h:form id="fomModal" >
					<center>
						<div style="margin-left: 40px; margin-bottom: 30px" class="grid-9-12" >
							<h:outputText styleClass="infoRegistroNaoEnc" value="#{msg['info.MSG_02']}"  />
						</div>	
						 <div class="field-clear"></div>
						<div style="margin-left: 60px" class="grid-3-12" >
							<a4j:commandButton ajaxSingle="true" value="Confirmar" action="#{usersCadastro.excluir}" 
								id="btnConfirmar" styleClass="form-button"
								reRender="pgMensagens,usersTable,idfsDadosPessoais" oncomplete="Richfaces.hideModalPanel('modalPanelConfirmaExcluir');"  style="width=50px">
								
							</a4j:commandButton>
						</div>	
						<div style="margin-left: 10px" class="grid-3-12" >
							<a4j:commandButton ajaxSingle="true" value="Cancelar" 				id="btnCancelar" styleClass="form-button"
								onclick="Richfaces.hideModalPanel('modalPanelConfirmaExcluir');"  style="width=50px">
							</a4j:commandButton>
						</div>	
					</center>
		</h:form>
		</div>
		</rich:modalPanel>
	
	<t:saveState  value="#{usersCadastro.listaAuthority}"/>
	<t:saveState  value="#{usersCadastro.listaIgrejasSelecionadas}"/>
	<t:saveState  value="#{usersCadastro.authority}"/>
	<t:saveState  value="#{usersCadastro.users}"/>
	<t:saveState  value="#{usersCadastro.edicao}"/>
	<t:saveState  value="#{usersCadastro.listaSelctItensIgrejas}"/>
	<t:saveState  value="#{usersCadastro.listaSelctItensIgrejasSelecionada}"/>
	<t:saveState  value="#{usersCadastro.username}"/> 
	<t:saveState  value="#{usersCadastro.listaIgrejas}"/> 
	</ui:define>
</ui:composition>

